package cn.zch.soft.util.date.compareDate;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
public class CompareDate {
  public static void main(String[] args) {
    String initTime = "2016-12-15";
    Integer a = CompareDate.daysBetween(initTime, CompareDate.getNowTime());
    System.out.println(a);
  }
  public static int daysBetween(String smdate, String bdate) {
    SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
    Calendar cal = Calendar.getInstance();
    long time1 = 0;
    long time2 = 0;
    try {
      cal.setTime(sdf.parse(smdate));
      time1 = cal.getTimeInMillis();
      cal.setTime(sdf.parse(bdate));
      time2 = cal.getTimeInMillis();
    }
    catch (Exception e) {
      e.printStackTrace();
    }
    long between_days = (time2 - time1) / (1000 * 3600 * 24);
    return Integer.parseInt(String.valueOf(between_days));
  }
  public static String getNowTime() {
    SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd");// 日期格式化
    return df.format(new Date());
  }
}
